package com.sky.asecpt;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Method;

@Slf4j
@Component
@Aspect // 切面类
public class LogAspect {

    @Resource
    private RedisTemplate redisTemplate;

    @Around("@annotation(com.sky.asecpt.anno.Log)")
    public void recordLog(ProceedingJoinPoint joinPoint) throws Throwable {

        // 获取对象
        Object target = joinPoint.getTarget();
        log.info("target={}",target);
        Method declaredMethod = target.getClass().getDeclaredMethod("getSky");

        // 用反射获取对象get方法
        declaredMethod.setAccessible(true);
        Object invoke = declaredMethod.invoke(target);

        // 用反射获取值
        log.info("invok={}",invoke);

    }


}

